//
//  TribalSelectedBoxCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/4.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "TribalSelectedBoxCell.h"

@implementation TribalSelectedBoxCell

- (void)setupUI{
    
    [self addSubview:self.titleLab];
    [self addSubview:self.detailLab];
    [self addSubview:self.icon];
    [self addSubview:self.line];
}

- (void)setupLayout{
    
    self.height = 54;
    {
        _titleLab.size = CGSizeMake(KScreenWidth - 100, 18);
        _titleLab.mj_x = 20;
        _titleLab.mj_y = (self.height - _titleLab.height)/2.0;
    }
    
    {
        _detailLab.size = CGSizeMake(100, 18);
        _detailLab.mj_x = KScreenWidth - _detailLab.width - 20;
        _detailLab.mj_y = (self.height - _detailLab.height)/2.0;
        
    }
    
    {
        _icon.size = CGSizeMake(16, 16);
        _icon.mj_x = KScreenWidth - _icon.width - 30;
        _icon.mj_y = (self.height - _icon.height)/2.0;
        
    }
    
    {
        _line.size = CGSizeMake(12, 2);
        _line.mj_x = 37;
        _line.mj_y = _titleLab.bottom +5;

    }
    
}

#pragma mark - setter methods

- (void)setType:(NSNumber *)type{
    
    if ([type integerValue] == 0) {
        _titleLab.text = @"请选择";
        _titleLab.textColor = UIColorFromRGB(0x262626);
        _titleLab.font = mMediumFont(15);
        _icon.hidden = YES;
        _detailLab.hidden = YES;
        _line.hidden = NO;
    }else{
        _titleLab.text = @"";
        _titleLab.textColor = UIColorFromRGB(0x999999);
        _titleLab.font = mFont(15);
        _icon.hidden = YES;
        _detailLab.hidden = YES;
        _line.hidden = YES;
    }
}


- (void)setItem:(id)item{
    
    if ([item isKindOfClass: [SelectTribes class] ]) {
        SelectTribes *obj = (SelectTribes *)item;
        _titleLab.text = obj.provinceName;
        
        BOOL isOpen = [obj.isOpen integerValue] == 1;
        [self updateItemByIsOpen:isOpen];
    }
    
    if ([item isKindOfClass: [CityItem class] ]) {
        CityItem *obj = (CityItem *)item;
        _titleLab.text = obj.ctiyName;
        BOOL isOpen = [obj.isOpen integerValue] == 1;
        [self updateItemByIsOpen:isOpen];
    }
    
    
    if ([item isKindOfClass: [AreaItem class] ]) {
        AreaItem *obj = (AreaItem *)item;
        _titleLab.text = obj.areaName;
        BOOL isOpen = [obj.isOpen integerValue] == 1;
        [self updateItemByIsOpen:isOpen];
    }
    
    if ([item isKindOfClass: [TribeItem class] ]) {
        TribeItem *obj = (TribeItem *)item;
        _titleLab.text = obj.tribeName;

        BOOL isOpen = [obj.isOpen integerValue] == 1;
        [self updateItemByIsOpen:isOpen];
    }
}


- (void)updateItemByIsOpen:(BOOL)isOpen
{
    if (isOpen) {
        _icon.hidden = NO;
        _detailLab.hidden = YES;
    }else{
        _icon.hidden = YES;
        _detailLab.hidden = NO;
    }
}


#pragma mark - getter methods

- (UILabel *)titleLab{
    
    if (!_titleLab) {
        _titleLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x999999) font:mFont(15) textAliment:0];
    }
    return _titleLab;
}

- (UILabel *)detailLab{
    
    if (!_detailLab) {
        _detailLab = [UILabel makeLabelWithText:@"此区域未开通" textColor:UIColorFromRGB(0x999999) font:mFont(12) textAliment:2];
        _detailLab.hidden = YES;
    }
    return _detailLab;
}

- (UIImageView *)icon{
    
    if (!_icon) {
        _icon = [UIImageView makeImageByImageName:@"adopt_adoptdetail_agreement" cornerRadius:0];
        _icon.hidden = YES;
    }
    return _icon;
}

- (UIView *)line{
    
    if (!_line) {
        _line = [UIView makeViewBgColor:mMainColor cornerRadius:0];
        _line.hidden = YES;
    }
    return _line;
}


@end

